home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / SystemCode / clickUtils.tcl < prev    next >
Encoding:
Text File  |  2001-01-17  |  6.0 KB  |  254 lines

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  AlphaTcl - core Tcl engine
  4.  # 
  5.  #  FILE: "clickUtils.tcl"
  6.  #                                    created: 11/2/96 {9:17:08 am} 
  7.  #                                last update: 01/17/2001 {15:57:41 PM} 
  8.  ##
  9.  
  10. # ◊◊◊◊ Option click in titlebar ◊◊◊◊ #
  11.  
  12. # Now doesn't add anything extra for windows which are not saved to disk. 
  13. # To deal with shells and other similar windows.  More general than only
  14. # doing this for shell mode.
  15. proc optClickTB_List {} {
  16.     global minItemsInTitlePopup
  17.     set lines [mode::proc OptionTitlebar]
  18.     if {[llength $lines] < $minItemsInTitlePopup} {
  19.     return [::OptionTitlebar $lines]
  20.     } else {
  21.     return $lines
  22.     }
  23. }
  24.  
  25. proc ::OptionTitlebar {{lines ""}} {
  26.     if {[file exists [win::StripCount [win::Current]]]} {
  27.     pushd [file dirname [win::Current]]
  28.     if {[llength $lines]} {
  29.         eval lappend lines "-" [glob -nocomplain *]
  30.     } else {
  31.         set lines [glob -nocomplain *]
  32.     }
  33.     popd
  34.     }
  35.     return $lines
  36. }
  37.  
  38. ## 
  39.  # -------------------------------------------------------------------------
  40.  #     
  41.  # "optClickTB_Pick" --
  42.  #    
  43.  #  Called when you select an item from the option-click pop-up.  Call a
  44.  #  mode-specific procedure if possible, else assume it's a file in the
  45.  #  same directory as the current window, and open it.  If the mode
  46.  #  specific procedure ends in an error, we use the default version. 
  47.  # -------------------------------------------------------------------------
  48.  ##
  49. proc optClickTB_Pick {item} {
  50.     if {[catch {mode::proc OptionTitlebarSelect $item}]} {
  51.     ::OptionTitlebarSelect $item
  52.     }
  53. }
  54.  
  55. proc ::OptionTitlebarSelect {item} {
  56.     if {[file isdirectory [file join [file dirname [win::Current]] $item]]} {
  57.     file::showInFinder [file join [file dirname [win::Current]] $item]
  58.     } else {
  59.     file::tryToOpen $item
  60.     }
  61. }
  62.  
  63. # ◊◊◊◊ Command click on window title ◊◊◊◊ #
  64.  
  65. # Called from Alpha when titlebar "title" menu selected (command-mouse).
  66. proc getTitleBarPath {} {
  67.     set win [win::Current]
  68.     
  69.     # If a hooked procedure can handle this, let it.
  70.     if {![catch [list hook::callUntilOk titlebarListHook * $win] res]} {
  71.     return $res
  72.     }
  73.  
  74.     return $win
  75. }
  76.  
  77. proc titlebar {name} {
  78.     set win [win::Current]
  79.     
  80.     # If a hooked procedure can handle this, let it.
  81.     if {[hook::callUntil titlebarSelectHook * $win $name]} {
  82.     return
  83.     }
  84.     
  85.     # To avoid troubles on Windoze with paths...
  86.     set name [file::ensureStandardPath $name]
  87.     if {$name == $win} {
  88.     if {[key::shiftPressed]} {
  89.         file::showInFinder
  90.     } else {
  91.         putScrap $name
  92.         message "Copied full path of '[file tail $name]' to the Clipboard."
  93.     }
  94.     } else {
  95.     if {[key::shiftPressed]} {
  96.         file::showInFinder $name
  97.     } else {
  98.         findFile $name
  99.     }
  100.     }
  101. }
  102.  
  103. # ◊◊◊◊ Command Double Click ◊◊◊◊ #
  104.  
  105. proc cmdDoubleClick {{from -1} {to -1} {shift 0} {option 0} {control 0}} {
  106.     global mode
  107.     
  108.     if {[expandURL] != ""} {
  109.     sendUrl [getSelect]
  110.     } else {
  111.     if {$from < 0} {
  112.         set from [getPos]
  113.         set to [selEnd]
  114.         if {[pos::compare $from == $to]} {
  115.         hiliteWord
  116.         set from [getPos]
  117.         set to [selEnd]
  118.         }
  119.     }
  120.     if {[set proc [mode::getProc DblClick]] != ""} {
  121.         if {[llength [info args $proc]] == 2} {
  122.         $proc $from $to
  123.         } else {
  124.         $proc $from $to $shift $option $control
  125.         }
  126.     } else {
  127.         message "No docs"
  128.     }
  129.     }    
  130. }
  131.  
  132. proc commandClick {from to url} {
  133.     select $from
  134.     for {set i 0} {$i < 200} {incr i} {}
  135.     select $from $to
  136.     for {set i 0} {$i < 200} {incr i} {}
  137.     select $from
  138.     for {set i 0} {$i < 200} {incr i} {}
  139.     select $from $to
  140.     url::execute $url
  141. }    
  142.  
  143. # ◊◊◊◊ URL handling ◊◊◊◊ #
  144.  
  145. # (WTP 7/30/95) Slightly improved 'sendUrl'.
  146. # By accepting a text arg, this can now be used to make sendUrl 
  147. # hypertext links (useful for "mailto" links in documentation, f'rinstance) 
  148. #===============================================================================
  149.  
  150. proc sendUrl {{text {}}} {
  151.     if {$text == {}} { catch {set text [getSelect]} }
  152.     if {$text == {}} { set text [prompt {URL?} {}] }
  153.     if {[string length $text] == 0} { return }
  154.     url::execute $text
  155. }
  156.  
  157. proc expandURL {} {
  158.     set pos [getPos]
  159.     set beg [lineStart $pos]
  160.     set whe [search -s -n -f 1 -r 1 -i 1 -m 0 -l [nextLineStart $pos] \
  161.       {[a-zA-Z0-9]+://[a-zA-Z/._0-9%~?\&=,-]+} $beg]
  162.     if {[string length $whe]} {
  163.     if {([pos::compare $pos >= [lindex $whe 0]]) \
  164.       && ([pos::compare $pos < [lindex $whe 1]])} {
  165.         eval select $whe
  166.         return $whe
  167.     }
  168.     }
  169. }
  170.  
  171.  
  172.  
  173. # ◊◊◊◊ Printing helpers ◊◊◊◊ #
  174.  
  175. proc printLeftHeader {pg {f ""}} {
  176.     global printHeader printHeaderTime printHeaderFullPath
  177.     
  178.     if {!$printHeader} return
  179.     
  180.     if {$f == ""} {set f [win::Current]}
  181.     if {$printHeaderFullPath} {
  182.     set text $f
  183.     } else {
  184.     set text [file tail $f]
  185.     }
  186.     
  187.     if {$printHeaderTime} {
  188.     append text "      [join [mtime [now] short]]"
  189.     }
  190.     return $text
  191. }
  192.  
  193. proc printRightHeader {pg {f ""}} {
  194.     global printHeader
  195.     if {!$printHeader} return
  196.     return "Page $pg"
  197. }
  198.  
  199. proc printAll {} {
  200.     foreach f [winNames -f] {
  201.     print $f
  202.     }
  203. }
  204.  
  205. # ◊◊◊◊ Spellcheck helpers ◊◊◊◊ #
  206.  
  207. #================================================================================
  208. # Excalibur is the only Mac spell-checker that I know of which will handle 
  209. # LaTeX as well as ordinary text.
  210.  
  211. array set spellCheckAppSignatures {
  212.     Excalibur XCLB
  213. }
  214.  
  215. array set spellCheckAppScripts {
  216.     Excalibur {
  217.     {sendOpenEvent noReply $quotedSig $filename}
  218.     }
  219. }
  220.  
  221. proc spellcheckWindow {} {
  222.     global spellCheckSig
  223.  
  224.     if {[winDirty]} {
  225.     if {[dialog::yesno "Save '[win::CurrentTail]'?"]} {
  226.         save
  227.     }
  228.     }
  229.     app::runScript spellCheck "Spell Checker" [win::StripCount [win::Current]]
  230.     hook::register resumeModifiedHook spellcheckResume [win::Current]
  231. }
  232.  
  233. proc spellcheckResume {name mod} {
  234.     if {$mod} {
  235.     bringToFront $name
  236.     revert
  237.     }
  238.     hook::deregister resumeModifiedHook spellcheckResume $name
  239. }
  240.  
  241. proc spellcheckSelection {} {
  242.     global spellCheckSig
  243.     if {[pos::compare [getPos] == [selEnd]]} {
  244.     beep
  245.     message "No selection"
  246.     return
  247.     }
  248.     copy
  249.     set name [app::launchBackSigs XCLB spellCheckSig "Please locate your spell checker"]
  250.     switchTo $name
  251. }
  252.  
  253.  
  254.